package com.example.task;

import com.example.service.Impl.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

//@Component
public class WebSocketTask {
    @Autowired
    private WebSocketService webSocketService;

    @Scheduled(cron = "0/5 * * * * ?")
    public void sendMessageToClient() {
        webSocketService.sendMessage("这是来自服务端的消息:" +
                DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now()));
    }

}
